<?php
require_once(dirname(__FILE__)."/../config/session.php");
require_once(dirname(__FILE__)."/../config/config.inc.php");
require_once(dirname(__FILE__)."/../libs/string/libstr.php");
require_once(dirname(__FILE__)."/../libs/dbclass/dbconn.php");
require_once(dirname(__FILE__)."/../libs/dbclass/dbservice.php");
require_once(dirname(__FILE__)."/../libs/login/login.php");
require_once(dirname(__FILE__)."/../libs/io/fileclass.php");
$mc=new libstr();
$db=new dbconn();
$dbs=new dbservice();
$lp=new login();
$fil=new fileclass();
set_time_limit(0);
ob_implicit_flush();
function getfilename($str,$s=0)
{
	if(ereg("/",$str)==1)
	{}else
	{
		return $str;
	}
	$str=split("/",$str);
	if($s==1)
	{
		return $str[count($str)-2];
	}
	return $str[count($str)-1];
}
function getkz($str,$s=1)
{
$str=split("\.",$str);
return $str[$s];
}
if($mc->Ismp($_POST["getdata"])!="")
{
    $kop=$db->dvstr("select * from xinghao_content where id=".$_POST["fid"]."");
	$kop2=$db->dvstr("select topicname from product_content where codeid=".$kop["codeid"]."");
	$kop1=$db->dvstr("select * from keycontent where keycode='".$_POST["codeid"]."'");
	$fname1=getfilename($kop["x_url"]);
	$fname2=$_POST["codeid"].$lp->getsession("userno")."_".getfilename($kop["x_url"]);
	$fname3=str_replace("—","-",str_replace(" ","",trim($kop2["topicname"])))."(".getkz($fname1,0)."-".$lp->getsession("userno").").".getkz($fname1);
	$thefilepath1=$fil->getrootdirpath()."\\uploadfile\\down\\".$fname1;
	$thefilepath2=$fil->getrootdirpath()."\\uploadfile\\tmpdata\\".$fname2;
	$thefilepath3=$fil->getrootdirpath()."\\uploadfile\\tmpdata\\".$fname3;
    
	if($fil->file_exit($thefilepath3))
	{
		echo $mc->gethost()."/uploadfile/tmpdata/".$fname3;
		exit();
	}
	if(!$fil->file_exit($thefilepath1))
	{
		echo "xq0";
		exit();
	}

	if(!extension_loaded('sockets'))
	{
		echo "xq1";
		exit();
	}
	
	$server_ip="127.0.0.1";
	$port = "9911";
	$buf= $thefilepath1."[a]".$thefilepath2."[a]1A31751F539D7B948252CB350BDA98E60C4049468B1635241D3DBE03B6D780364744859B58C39F2BD4E6598C9C7F3017AB4BF653D4CB91E1752C88408CF0F792204AEEFAEE565758AC51CE957B6F253744DF72171123D954B2D77D4D3B1E47FF18E96A29DC8ECFC6FF51E01423874F6CB3A3D126D0F9F18BF5E16DCBC80EC4F2".trim($kop1["keydata"]);
	$sock=socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

	if(!$sock){
		echo "xq2";
		exit();
	}


	if(!socket_sendto($sock,$buf,strlen($buf),0,$server_ip,$port)){
		echo "xq3";
		socket_close($sock);
		exit();
	}
	socket_close($sock);
	
	sleep(6);
    if($fil->file_exit($thefilepath2))
	{
	    if($fil->file_copy($thefilepath2,iconv("UTF-8","gb2312", $thefilepath3))){
		echo $mc->gethost()."/uploadfile/tmpdata/".$fname3;
		$fil->delete_file($thefilepath2.".log");
		$fil->delete_file($thefilepath2);
		exit();
		}
	}else
	{
	sleep(10);
	  if($fil->file_exit($thefilepath2))
	{
		   if($fil->file_copy($thefilepath2,iconv("UTF-8","gb2312", $thefilepath3))){
		echo $mc->gethost()."/uploadfile/tmpdata/".$fname3;
		$fil->delete_file($thefilepath2.".log");
		$fil->delete_file($thefilepath2);
		exit();
		}
	}
	}
	echo "kkkno";

}

?>